public class PersonTester {

	public static void main(String[] args) {
		
		PersonTester tester = new PersonTester();
		tester.testGrandChildToGreatGrandMotherRelationship(1);
		tester.testManToStrangerRelationship(2);
		tester.testGruncleRelationship(3);
		tester.testManToWifesCousinRelationship(4);
	}
	
	
	public void testManToWifesCousinRelationship(int testId) {
		// man
		Person jack = new MyPerson("Jack", 1, Person.MALE);		
		
		// wife
		Person  jill = new MyPerson("Jill", 2, Person.FEMALE);
		jack.setSpouse(jill);
		
		// wife's mother
		Person beth = new MyPerson("Beth", 3, Person.FEMALE);
		jill.addParent(beth);
		
		// wife's grandmother
		Person mary = new MyPerson("Mary", 4, Person.FEMALE);
		beth.addParent(mary);
		
		// wife's uncle
		Person dave = new MyPerson("Dave", 5, Person.MALE);
		mary.addChild(dave);

		//wife's aunt
		Person sally = new MyPerson("Sally", 6, Person.FEMALE);
		dave.setSpouse(sally);
		
		// wife's cousin
		Person andrew = new MyPerson("Andrew", 7, Person.MALE);
		sally.addChild(andrew);
		
		// wife's cousin's wife
		Person janet = new MyPerson("Janet", 8, Person.FEMALE);
		andrew.setSpouse(janet);
		
		this.performTestAndPrintResults(testId, jack, janet, "Wife's Cousin", true);
		// test the reverse relationship
		this.performTestAndPrintResults(testId + 1, janet, jack, "Cousin's Husband", true);
		
	}
	
	private void performTestAndPrintResults(int testCaseNumber, Person p1, Person p2, String relationship, boolean related) {
		
		String relatedOrNot = "not related";
		if(related) {
			relatedOrNot = "related";
		}
		
		System.out.print("TEST CASE #" + testCaseNumber);
		if(p1.isRelated(p2) == related) {
			System.out.print("(PASS): " + p1.getName() +  " and " + p2.getName() + "(" + relationship + ") are " + relatedOrNot + ". Your code agrees!\n");
		}
		else {
			System.out.print("(FAIL): " + p1.getName() + " and " + p2.getName() + "(" + relationship + ") are " + relatedOrNot + ". Your code disagrees!\n");
		}
		
	}


	public void testManToStrangerRelationship(int testId) {
	
		MyPerson jack = new MyPerson("Jack" , 1, Person.MALE);
		MyPerson stranger = new MyPerson("Perry" , 2, Person.MALE);
		
		this.performTestAndPrintResults(testId, jack, stranger, "Stranger", false);
				
	}


	public void testGrandChildToGreatGrandMotherRelationship(int testId) {
	
		MyPerson man = new MyPerson("Jack", 1, Person.MALE);
		
		//mother
		MyPerson  mother = new MyPerson("Jill", 2, Person.FEMALE);
		man.addParent(mother);
		
		// grandMother
		MyPerson gm = new MyPerson("Beth", 3, Person.FEMALE);
		mother.addParent(gm);
		
		// great-grandMother
		MyPerson ggm = new MyPerson("Mary", 4, Person.FEMALE);
		gm.addParent(ggm);
	
		//child
		MyPerson  child = new MyPerson("Peter", 5, Person.MALE);
		man.addChild(child);
	
		//grandChild
		MyPerson  grandChild = new MyPerson("Dave", 6, Person.MALE);
		child.addChild(grandChild);
		
		// is my grandChild related to my great-grandMother
		this.performTestAndPrintResults(testId, grandChild, ggm, "Great-Great-Great-GrandMa", true);
	}


	public void testGruncleRelationship(int testId) {

		// A gruncle is someone who is both a Grandfather & an Uncle to another person

		// child
		Person child = new MyPerson("Billy", 0, Person.MALE);
		
		Person father = new MyPerson("Jack", 1, Person.MALE);		
		Person  mother = new MyPerson("Jill", 2, Person.FEMALE);
		father.setSpouse(mother);
		father.addChild(child);
	
		// father's father (grand father)
		Person grandPa = new MyPerson("Dave", 3, Person.MALE);
		father.addParent(grandPa);
		
		// mother's sister (aunt)
		Person gm = new MyPerson("Beth", 4, Person.FEMALE);
		mother.addParent(gm);			
		Person aunt = new MyPerson("Shelly", 5, Person.FEMALE);
		gm.addChild(aunt);
	
		// father's father marries mother's sister
		grandPa.setSpouse(aunt);
		
		Person gruncle = grandPa;
		// am i related to wife's uncle's wife?
		this.performTestAndPrintResults(testId, child, gruncle, "Gruncle", true);	
		
	
	}

}
